//
function sureAddBook(){
    //console.log("0000000000000000000000000")
    var bookName = $("#input_notebook").val().trim();
    //console.log(bookName);
    //TODO 格式检查
    //发送ajax
    $.ajax({
        url: base_url + "/notebook/add.do",
        type: "post",
        data: {"userId":userId,"bookName":bookName},
        dataType: "json",
        success:function(result){
            console.log(result);
            if(result.status == 0){
                //关闭对话框
                closeWindow();
                //添加笔记li
                var bookId = result.data;
                createBookLi(bookName,bookId);
                //提示成功
                alert(result.msg)
            }
        },
        error:function(){
            alert("添加笔记本失败")
        }
    })

}
//createBookLi方法
function createBookLi(bookName,bookId){
    var s_li  = '<li class="online">';
    s_li += '<a>';
    s_li += '<i class="fa fa-book" title="online" rel="tooltip-bottom">';
    s_li += '</i>' + bookName;
    s_li += '</a></li>';
    var $li = $(s_li);
    //将bookId绑到$li中
    $li.data("bookId",bookId);
    //将$li主驾到ul
    $("#book_list").append($li);
}
//加载笔记本列表
function loadUserBooks(){
   // $(function (){
        //其他操作
        $.ajax({
            url: base_url + "/notebook/loadbooks.do",
            type: "post",
            data: {"userId":userId},
            dataType: "json",
            success:function(result){
                //console.log(result)
                var books = result.data;
                for(var i=0;i<books.length;i++){
                    var bookName = books[i].cn_notebook_name;
                    var bookId = books[i].cn_notebook_id;
                    //拼接一个li
                    createBookLi(bookName, bookId);

                     //拼接一个li

                     // var s_li  = '<li class="online">';
                     // s_li += '<a>';
                     // s_li += '<i class="fa fa-book" title="online" rel="tooltip-bottom">';
                     // s_li += '</i>' + bookName;
                     // s_li += '</a></li>';
                     // var $li = $(s_li);
                     // //将bookId绑到$li中
                     // $li.data("bookId",bookId);
                     //将$li添加到ul
                     // $("#book_list").append($li);

                }
            },
            error:function () {
                alert("加载笔记失败")
            }
        })
   // })
}